class Department < ActiveRecord::Base

  has_many :designers

  validates_presence_of :name
  validates_uniqueness_of :name

  def paying_total_amount
    DesignerWorkItem.sum :should_be_payed,
      :conditions => [
        'designers.department_id = ? and stages.pay_status = ? ',
        id,
        'paying'
      ],
      :include => [:designer,:stage]
  end

  def payed_total_amount
    DesignerWorkItem.sum :should_be_payed,
      :conditions => [
        'designers.department_id = ? and stages.pay_status = ? ',
        id,
        'payed'
      ],
      :include => [:designer,:stage]
  end

  def paused_total_amount
    DesignerWorkItem.sum :should_be_payed,
      :conditions => [
        'designers.department_id = ? and stages.pay_status = ? ',
        id,
        'paused'
      ],
      :include => [:designer,:stage]
  end
end

